package com.sx.zongzhi.presenter;

import com.sx.zongzhi.MyApplication;
import com.sx.zongzhi.bean.KeyPunishDetailBean;
import com.sx.zongzhi.modle.ApiManager;
import com.sx.zongzhi.net.BaseCallBack;
import com.sx.zongzhi.net.BaseResult;
import com.sx.zongzhi.view.IKeyAreaAddView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by XZY on 2017/11/30.
 *重点地区排查整治添加/更新
 */
public class KeyPunishAddPest {

    private IKeyAreaAddView areaAddView;

    public KeyPunishAddPest(IKeyAreaAddView areaAddView) {
        this.areaAddView=areaAddView;
    }


    /**
     *
     * @param path 地址类型
     * @param id 重点地区id
     * @param detailBean
     * @param upList 新增图片地址
     *  @param removeList 移除图片的id
     */
    public void AddKeyPunish(String path, String id, String orgId, KeyPunishDetailBean detailBean,
                             List<String> upList,List<String> removeList){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("enterprise.id", id);//重点地区id
        map.put("enterprise.organization.id", orgId);//网格
        map.put("enterprise.securityKeyAreas",detailBean.getSecurityKeyAreas());
        map.put("enterprise.securityProblems.id", detailBean.getSecurityProblems().getId());
        map.put("enterprise.involvedType.id", detailBean.getInvolvedType().getId());
        map.put("enterprise.relateArea", detailBean.getRelateArea());
        map.put("enterprise.repairLeaderUnit", detailBean.getRepairLeaderUnit());
        map.put("enterprise.repairPartakeUnit", detailBean.getRepairPartakeUnit());
        map.put("enterprise.leaderUnitDirector", detailBean.getLeaderUnitDirector());
        map.put("enterprise.leaderUnitDirectorTelephone", detailBean.getLeaderUnitDirectorTelephone());
        map.put("enterprise.leaderUnitDirectorMobileNumber",  detailBean.getLeaderUnitDirectorMobileNumber());
        map.put("enterprise.repairTimelimit",  detailBean.getRepairTimelimit());
        map.put("enterprise.solveNumber",  detailBean.getSolveNumber());
        map.put("enterprise.investigatePunishNumber", detailBean.getInvestigatePunishNumber());
        map.put("enterprise.repairSituation",  detailBean.getRepairSituation());
        map.put("enterprise.effectEvaluate.id",  detailBean.getEffectEvaluate().getId());
        if (upList!=null&&upList.size()>0) {
            String str="";
            int count=upList.size();
            for (int i=0;i<count;i++){
                if (i==count-1){
                    str=str+upList.get(i);
                }else {
                    str=str+upList.get(i)+",";
                }
            }
            map.put("filePaths", str);
        }
//        if (removeList!=null&&removeList.size()>0){
//            String str="";
//            int count=removeList.size();
//            for (int i=0;i<count;i++){
//                if (i==count-1){
//                    str=str+removeList.get(i);
//                }else {
//                    str=str+removeList.get(i)+",";
//                }
//            }
//            map.put("enterprise.removeId", str);
//        }
        if (removeList!=null && removeList.size()>0){
            for (int i = 0 ; i < removeList.size() ; i ++){
                map.put("enterprise.removeId["+i+"]",removeList.get(i));
            }
        }
        new ApiManager().AddKeyPunish(path,map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                areaAddView.addSuccess(response.getData());
            }
            @Override
            public void onFailures(String message) {
                areaAddView.showError(message);
            }
        });
    }

    /**
     * 判断是否有相同的名称
     * @param path 地址类别
     * @param orgId 网格id
     * @param name 名称
     * @param id (建议新增时不提交,更新时提交当前更改重点区域id)
     */
    public void AddKeyPunish(String path,String orgId,String name,String id){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("enterprise.organization.id", orgId);//网格
        map.put("enterprise.securityKeyAreas",name);
        map.put("enterprise.id", id);//地区id
        new ApiManager().AddKeyPunish(path,map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                areaAddView.nameSuccess(response.getData());
            }
            @Override
            public void onFailures(String message) {
                areaAddView.showError(message);
            }
        });
    }

}
